import fetch from 'common/src/utils/fetch';
import baseUrl from './env';

//指定审核人
export function assign(data) {
    return fetch({
        url: `${baseUrl}ug/exchanges/assign`,
        method: 'post',
        data
    })
}
//取消指定审核人
export function cancel(data) {
    return fetch({
        url: `${baseUrl}ug/exchanges/cancel`,
        method: 'post',
        data
    })
}
//查询学生基本信息
export function queryStuInfo(data) {
    let defaultData = {
        studentId: '',
        isIllegal: false,//是否校验学号非法
        isCurrentFaculty: false,//是否需要校验教务员仅可以代申请本学院学生
        isStatus: false,//是否需要校验学生在籍
        isUndergraduate: false//是否需要校验是否本科生
    }
    return fetch({
        url: `${baseUrl}ug/exchanges/student`,
        method: 'post',
        data: Object.assign(defaultData, data)
    })
}
//交流导出
export function exportApplyList(data) {
    let keys = Object.keys(data).map(item => { return item; });
    let params = keys.reduce((prev, curr, index) => {
        prev += curr + '=' + data[curr];
        if (index < keys.length - 1) {
            prev += '&';
        }
        return prev;
    }, '');
    let url = `${baseUrl}ug/exchanges/exportApplyList`;
    params && (url += `?${params}`);
    window.open(url);
}
/**
 * 撤回的接口，内部进行调用工作流，并将原来的状态更改为草稿中
 * @param {} data 
 */
export function recall(data) {
    return fetch({
        url: '/api/workflow/approval/recall',
        method: 'post',
        data: data
    });
}

/**
 * 撤回接口，本科生国际交流私有
 * id  主键ID、   agencyWorkflowNo
 */
export function recallPrivate(data) {
    return fetch({
        url: `${baseUrl}ug/exchanges/recall?id=${data.id}&&agencyWorkflowNo=${data.agencyWorkflowNo}`,
        method: 'get'
    })
}
//交流返校确认
export function affirm(ids){
    return fetch ({
        url:`${baseUrl}ug/exchanges/affirm?ids=${ids}`,
        method:'get'
    })
}